#!/bin/sh -xe

body="{ \"msgtype\": \"text\", \"text\": { 
    \"content\": \"${2}\" "

user_name=$(curl "https://f2e.qtrade.com.cn/cr/external/get_wechat_id?gitlab_user_id=${GITLAB_USER_ID}")

if [ $user_name ]; then
  body="${body}, \"mentioned_list\":[\"${user_name}\"],"
fi

body="${body} } }"

curl "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${1}" \
  -H 'Content-Type: application/json' \
  -d "$body"